package cn.iocoder.yudao.module.system.controller.admin.queryscenecondition;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.system.controller.admin.queryscenecondition.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.queryscenecondition.QuerySceneConditionDO;
import cn.iocoder.yudao.module.system.service.queryscenecondition.QuerySceneConditionService;

@Tag(name = "管理后台 - 查询场景条件")
@RestController
@RequestMapping("/system/query-scene-condition")
@Validated
public class QuerySceneConditionController {

    @Resource
    private QuerySceneConditionService querySceneConditionService;

    @PostMapping("/create")
    @Operation(summary = "创建查询场景条件")
    public CommonResult<Long> createQuerySceneCondition(@Valid @RequestBody QuerySceneConditionSaveReqVO createReqVO) {
        return success(querySceneConditionService.createQuerySceneCondition(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新查询场景条件")
    public CommonResult<Boolean> updateQuerySceneCondition(@Valid @RequestBody QuerySceneConditionSaveReqVO updateReqVO) {
        querySceneConditionService.updateQuerySceneCondition(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除查询场景条件")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteQuerySceneCondition(@RequestParam("id") Long id) {
        querySceneConditionService.deleteQuerySceneCondition(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得查询场景条件")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<QuerySceneConditionRespVO> getQuerySceneCondition(@RequestParam("id") Long id) {
        QuerySceneConditionDO querySceneCondition = querySceneConditionService.getQuerySceneCondition(id);
        return success(BeanUtils.toBean(querySceneCondition, QuerySceneConditionRespVO.class));
    }

    @GetMapping("/list")
    @Operation(summary = "获得查询场景条件")
    @Parameter(name = "sceneId", description = "编号", required = true, example = "1024")
    public CommonResult<List<QuerySceneConditionRespVO>> getQuerySceneConditionList(@RequestParam("sceneId") Long sceneId) {
        List<QuerySceneConditionDO> querySceneCondition = querySceneConditionService.getQuerySceneConditionBySceneId(sceneId);
        return success(BeanUtils.toBean(querySceneCondition, QuerySceneConditionRespVO.class));
    }


    @GetMapping("/page")
    @Operation(summary = "获得查询场景条件分页")
    public CommonResult<PageResult<QuerySceneConditionRespVO>> getQuerySceneConditionPage(@Valid QuerySceneConditionPageReqVO pageReqVO) {
        PageResult<QuerySceneConditionDO> pageResult = querySceneConditionService.getQuerySceneConditionPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, QuerySceneConditionRespVO.class));
    }


}